package com.contract.spirit.manage

import android.app.Activity
import android.graphics.Color
import com.azhon.appupdate.config.UpdateConfiguration
import com.azhon.appupdate.manager.DownloadManager
import com.contract.spirit.BuildConfig
import com.contract.spirit.R
import com.contract.spirit.bean.response.VersionInfoResponse

/**
 * @author zhengjun
 * @desc
 * @create at 2021/6/1 16:37
 */
object AppVersionUpdateManager {
     fun checkUpdata(activity: Activity, data: VersionInfoResponse?) {
        if (data != null) {
            val verinfo = data.verinfo
            val updateStatus = verinfo.updateStatus
            if (1 == updateStatus) {
                val configuration = UpdateConfiguration() //设置按钮的文字颜色
                    .setDialogButtonTextColor(Color.WHITE) //设置强制更新
                    .setForcedUpgrade(1 == verinfo.forceUpdate)
                DownloadManager.getInstance(activity).setApkName("contractSpirit.apk")
                    .setApkUrl(verinfo.downUrl)
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .setConfiguration(configuration)
                    .setApkSize(verinfo.size)
                    .setApkVersionName(verinfo.newVersion)
                    .setApkVersionCode(BuildConfig.VERSION_CODE + 1) //用来判断是否显示升级弹框
                    .setApkDescription(verinfo.content)
                    .download()
            }
        }
    }
}